import * as api from '@/apis/modules/register.js';

const register = {
	namespaced: true,
	state: {
		agentInfo: {}
	},
	mutations: {
		save(state, {field, payload}) {
		  if (Object.prototype.toString.call(payload) === '[object Object]') {
			state[field] = { ...state[field], ...payload }
		  } else {
			state[field] = payload
		  }
		}
	},
	actions: {
		register({ commit }, payload) {
			api.register(payload).then(res => console.log(res)).catch(err => console.log(err))
			
		},
		
		getAgentInfo({commit}, payload) {
			api.getAgentInfo(payload)
				.then(({data}) => {
					console.log(data)
					commit('save', {field: 'agentInfo', payload: data})
				})
		}
	}
}

export default register